<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<title>title</title>
	<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../css/aui.css" />
	<link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
	<link rel="stylesheet" type="text/css" href="../css/icons.css" />
	<script src="../script/jquery-1.9.1.min.js"></script>
	<script src="../script/bootstrap.min.js"></script>
	<style>
		.table tr:first-child {
			background: url(static/img/tableheader-bg.gif) no-repeat left top;
			background-color: #DCE9F2;
			border-top: 1px solid #CBD6DE;
			border-bottom: 1px solid #ADBECB;
			color: #467aa7;
			font-size: 13px;
			font-weight: bold;
		}

		.table {
			margin-bottom: 15px;
			width: 100%;
			border-collapse: collapse;
			font-size: 13px;
			margin-bottom: 15px;
			width: 100%;
			border-collapse: collapse;
		}

		.table td {
			height: 40px;
			text-align: center;
			border: 1px solid #CBD6DE;
			padding: 0;
			margin: 0;
			vertical-align: middle !important;
		}

		.hide {
			display: none;
		}

		.c1 {
			position: fixed;
			top: 0;
			bottom: 0;
			left: 0;
			right: 0;
			background: rgba(0, 0, 0, .5);
			z-index: 2;
		}

		.c2 {
			background-color: white;
			position: fixed;
			width: 300px;
			height: 300px;
			top: 50%;
			left: 50%;
			z-index: 3;
			margin-top: -150px;
			margin-left: -150px;
			padding-top: 2%;
			padding-left: 2%;
		}

		/*#chkHCTable{
				font-size: 10px;
		}*/
		option {
			font-size: 5px;
			/* 设置option的字体大小 */
		}
	</style>
</head>

<body>
	<header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
		<a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
			<span class="aui-iconfont aui-icon-left"></span>
		</a>
		<div class="aui-title" id="title">
			分层审核维护任务列表
		</div>
	</header>
	<div class="aui-content" style="margin-top:50px;">

		<div class="aui-form">

			<div class="aui-content aui-margin-b-15">
				<ul class="aui-list aui-form-list" style="font-size: 14px;">

					<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-label" style="font-size: 14px;">维护任务</div>
							<input type="text" class="aui-input" placeholder="选择维护任务"
								style="width: 80%;font-size: 14px;" id="chkTaskCode" value=""
								onclick="goSelectChkTask()">
							<i class="aui-input-addon aui-iconfont aui-icon-right" style="font-size: 1.6rem"
								onclick="goSelectChkTask()"></i>
						</div>
					</li>
					<!-- <li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-label" style="font-size: 14px;">执行状态</div>
							<div class="aui-list-item-input">
								<select id="zxState" style="font-size: 14px;">
									<option value="2" selected="true">进行</option>
									<option value="3">完成</option>
								</select>
							</div>
						</div>
					</li>
					<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-label" style="font-size: 14px;">执行结果</div>
							<div class="aui-list-item-input">
								<select id="zxResult" style="font-size: 14px;">
								</select>
							</div>
						</div>
					</li> -->
					<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-label" style="width:30%;font-size: 14px;">实际开始时间</div>
							<div class="aui-list-item-input" style="float:left;width: 70%;">
								<input type="text" id="actualBeginDate" onclick="showTime();">
							</div>
						</div>
					</li>
					<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-label" style="width:30%;font-size: 14px;">实际结束时间</div>
							<div class="aui-list-item-input" style="float:left;width: 70%;">
								<input type="text" id="actualEndDate" onclick="showTime3();">
							</div>
						</div>
					</li>

					<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-label" style="font-size: 14px;">区域</div>
							<div class="aui-list-item-input">
								<select id="areaCodeList" style="font-size: 14px;" onchange="changeArea()">
								</select>
							</div>
						</div>
					</li>
					<!-- <div class="aui-content" style="background-color: #ffffff">
						<ul class="aui-list-view aui-grid-view" id="imgslist">
							<li class="aui-list-view-cell aui-img aui-col-xs-4 aui-padded-5" id="addpic"
								onclick="imgClick()">
								<img class="aui-img-object" src="../image/add.jpg">
							</li>
						</ul>
					</div> -->
				</ul>
			</div>
			<ul id="myTab" class="nav nav-tabs" style="background-color: #F4F4F4;font-size: 13px;">
				<li class="active" style="width: 100%;text-align:center;"> <a href="#item" data-toggle="tab">检修项 </a>

				</li>

			</ul>
			<div id="myTabContent" class="tab-content">
				<div class="tab-pane fade in active" id="item">
					<div
						style="background-color:white; height: 100%;width: 100%;overflow-x: auto;-webkit-overflow-scrolling:touch;">
						<table id="chkItemTable" class="table" style='width:100%;'>
							<tbody id="chkItemTableHead"
								style="display: block; overflow-x: auto; white-space: nowrap;width: 100%">

							</tbody>
							<tbody id="chkItemTableBody">
							</tbody>
							<tbody id="chkItemTableBehind">
							</tbody>
						</table>
						<div class="aui-content">
							<div class="aui-content aui-content-padded" style="text-align:center;margin-bottom: 5%">
								<p>
								</p>
								<div class="aui-btn aui-btn-info" onclick="doAdd()"
									style="width: 100%;height: 100%;display: none;">
									<span class="aui-iconfont" style="font-size: 20px;">添加检修项</span>

								</div>
								<p></p>
							</div>
							<div class="aui-content aui-content-padded" style="text-align:center;margin-bottom: 5%">
								<p>
								</p>
								<div class="aui-btn aui-btn-info" onclick="doDel()"
									style="width: 100%;height: 100%;display: none;">
									<span class="aui-iconfont" style="font-size: 20px;">删除检修项</span>

								</div>
								<p></p>
							</div>

						</div>
					</div>
				</div>
			</div>
			<div class="aui-content aui-margin-b-15">
				<ul class="aui-list aui-form-list" style="font-size: 14px;">
					<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-label" style="font-size: 14px;">执行状态</div>
							<div class="aui-list-item-input">
								<select id="zxState" style="font-size: 14px;">
									<option value="2" selected="true">进行</option>
									<option value="3">完成</option>
								</select>
							</div>
						</div>
					</li>
					<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-label" style="font-size: 14px;">执行结果</div>
							<div class="aui-list-item-input">
								<select id="zxResult" style="font-size: 14px;">
								</select>
							</div>
						</div>
					</li>
				</ul>
			</div>
			<div class="aui-content aui-content-padded" style="text-align:center;margin-bottom: 5%">
				<p>
				</p>
				<div class="aui-btn aui-btn-info" onclick="show()" id="submitButton" style="width: 100%;height: 100%;">
					<span class="aui-iconfont" style="font-size: 20px;">提交数据</span>

				</div>
				<p></p>
			</div>
			<div id="shade" class="c1 hide"></div>
			<div id="modal" class="c2 hide">
				<p style="margin-left: 10px;font-size: 0.8rem;font-weight: 500;color: #212121;text-align: center;">
					存在异常问题，请选择处理人</p>
				<ul class="aui-list aui-form-list" style="margin-top: 4%;">
					<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-label" style="width:80%">审核区域负责人：</div>
							<div class="aui-list-item-input">
								<!-- <select id="processors">
								</select> -->
							</div>
						</div>
					</li>
					<li class="aui-list-item" style="display: none;">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-label">整改措施：</div>
							<div class="aui-list-item-input">
								<input type="text" id="measures"></input>
							</div>
						</div>
					</li>
					<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-label" style="width:75%">要求完成时间：</div>
							<div class="aui-list-item-input">
								<input type="text" id="finishDate" onclick="showTime2();">
							</div>
						</div>
					</li>
					<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-label">整改要求：</div>
							<div class="aui-list-item-input">
								<textarea id="countermeasure"></textarea>
							</div>
						</div>
					</li>
				</ul>
				<footer class="aui-bar aui-bar-tab" style="position: absolute;">
					<div class="aui-btn aui-btn-info" style="width:30%;margin-left:2%;" onclick="Hide()">取消</div>
					<div class="aui-btn aui-btn-info" style="width:30%;margin-left:10%;" onclick="doSave()">确定</div>
				</footer>
			</div>
		</div>
	</div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/hammer.min.js"></script>
<script type="text/javascript" src="../script/clickThrottle.js"></script>
<script>

	var taskId = "";
	var taskCode = "";
	var itemIds = "";
	var itemCodes = "";
	var itemNames = "";
	var itemModes = "";
	var itemValues = "";
	var itemMaxValues = "";
	var itemMinValues = "";
	var itemStandardValue = "";
	var itemExt01 = "";
	var josnList = [];
	var delItemIds = "";
	var str = "";
	var strHC = "";
	var strYQ = "";
	var imgSrcList = [];
	var processorsSelectValue = "";
	var finishDateIndexValue = "";
	var problemDescIndexValue = "";
	//检测维修耗材参数
	var HCId = "";
	var mrlGid = "";
	var mrlCode = "";
	var mrlName = "";
	var mrlExName = "";
	var qty = "";
	var measureName = "";
	var consumeType = "";
	var remark = "";
	var josnHCList = [];
	var delHCIds = "";

	//检测维修耗材仪器
	var YqId = "";
	var mrlYqGid = "";
	var mrlYqCode = "";
	var mrlYqName = "";
	var remarkYq = "";
	var josnYqList = [];
	var delYqIds = "";

	var YqIds = "";

	var areaId = "";
	var uiMediaScanner = null;
	var imageFilter = null;
	var imageBrowser = null;

	apiready = function () {
		// 引入多选模块
		uiMediaScanner = api.require('UIMediaScanner');
		// 引入过滤压缩模块
		imageFilter = api.require("imageFilter");
		// 引入图片浏览模块
		imageBrowser = api.require('imageBrowser');
		// doSearchProcessors()
	}
	function show() {
		var type = document.getElementById("zxResult").value;
		var taskState = document.getElementById("zxState").value;
		var areaSysid = document.getElementById("areaCodeList").value;
		var actualBeginDate = document.getElementById("actualBeginDate").value;
		if (actualBeginDate == "" || actualBeginDate == null || actualBeginDate == undefined) {
			api.toast({
				msg: '请选择实际开始时间！',
				duration: 3000
			});
			return;
		}
		var actualEndDate = document.getElementById("actualEndDate").value;
		if (actualEndDate == "" || actualEndDate == null || actualEndDate == undefined) {
			api.toast({
				msg: '请选择实际结束时间！',
				duration: 3000
			});
			return;
		}
		if (areaSysid == "" || areaSysid == null || areaSysid == undefined) {
			api.toast({
				msg: '请选择区域！',
				duration: 3000
			});
			return;
		}
		// if (type == '2' && taskState == '3') {
		// 	document.getElementById('modal').classList.remove('hide');
		// 	document.getElementById('shade').classList.remove('hide');
		// }
		//  else {
		doSave()
		// }
	}
	function Hide() {
		document.getElementById('modal').classList.add('hide');
		document.getElementById('shade').classList.add('hide');
	}
	function doSearchProcessors(areaId) {
		var un = localStorage.getItem('un');
		var serverUrl = localStorage.getItem('serverUrl');
		var url = serverUrl + "/app/getUtilComboxList";
		var data = {
			values: { ////以表单方式提交参数（JSON对象）
				tablename: "lpa_bas_area_user",
				column_name: "name",
				column_value: "code",
				condition: "area_gid = '" + areaId + "'",
				un: un
			}
		};
		api.ajax({
			url: url,
			method: 'post',
			dataType: 'json',
			timeout: 300,
			returnAll: false,
			async: false,
			data: data
		}, function (ret, err) {
			if (ret) {
				var data = JSON.stringify(ret);
				var map = eval("(" + data + ")");
				var list = eval(map.list);
				var html = "";
				for (var i = 0; i < list.length; i++) {
					html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
				}
				for (var j = 0; j < 30; j++) {
					var a = "processors" + j
					$api.html($api.byId(a), html);
				}
			}
		});
	}
	function changeArea() {
		var selectElement = document.getElementById('areaCodeList').value;
		doSearchProcessors(selectElement);
	}
	function doSearchAreaCodeList(areaId, areaIdOne) {
		var un = localStorage.getItem('un');
		var serverUrl = localStorage.getItem('serverUrl');
		var url = serverUrl + "/app/getUtilComboxList";
		var data = {
			values: { ////以表单方式提交参数（JSON对象）
				tablename: "lpa_bas_area",
				column_name: "name",
				column_value: "sysid",
				condition: "sysid = ANY(string_to_array('" + areaId + "', ','))",
				un: un
			}
		};
		api.ajax({
			url: url,
			method: 'post',
			dataType: 'json',
			timeout: 300,
			returnAll: false,
			async: false,
			data: data
		}, function (ret, err) {
			if (ret) {
				var data = JSON.stringify(ret);
				var map = eval("(" + data + ")");
				var list = eval(map.list);
				var html = "";
				for (var i = 0; i < list.length; i++) {
					html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
				}
				$api.html($api.byId("areaCodeList"), html);
				if (areaIdOne != "") {
					$("#areaCodeList").attr("value", areaIdOne);
					changeArea()
				}

			}

		});
	}

	function showTime() {
		var moduleTimer = api.require('moduleTimer');
		moduleTimer.showTimer({
			startTime: '2000-01-1 00:00',//可选择的起始时间
			endTime: '2099-12-31 23:59',//可选择的结束时间
			timeFormat: 'yyyy-MM-dd HH:mm:ss',//返回的时间格式，如果不传默认是yyyy-MM-dd HH:mm:ss
			selColor: '#079962'//选中的颜色值
		}, function (ret, err) {
			var actualBeginDate = ret;
			var text = document.getElementById("actualBeginDate");
			text.value = actualBeginDate;
		});
	}
	function showTime3() {
		var moduleTimer = api.require('moduleTimer');
		moduleTimer.showTimer({
			startTime: '2000-01-1 00:00',//可选择的起始时间
			endTime: '2099-12-31 23:59',//可选择的结束时间
			timeFormat: 'yyyy-MM-dd HH:mm:ss',//返回的时间格式，如果不传默认是yyyy-MM-dd HH:mm:ss
			selColor: '#079962'//选中的颜色值
		}, function (ret, err) {
			var actualEndDate = ret;
			var text = document.getElementById("actualEndDate");
			text.value = actualEndDate;
		});
	}
	function showTime2(id) {
		var moduleTimer = api.require('moduleTimer');
		moduleTimer.showTimer({
			startTime: '2000-01-1 00:00',//可选择的起始时间
			endTime: '2099-12-31 23:59',//可选择的结束时间
			timeFormat: 'yyyy-MM-dd HH:mm:ss',//返回的时间格式，如果不传默认是yyyy-MM-dd HH:mm:ss
			selColor: '#079962'//选中的颜色值
		}, function (ret, err) {
			var finishDate = ret;
			var text = document.getElementById(id);
			text.value = finishDate;
		});
	}

	function toScanner() {
		var moduleScanner = api.require('moduleScanner');
		var params = {
			top: 150,//扫描窗口的上边距
			width: 250,//扫描窗口的宽
			height: 250,//扫描窗口的高
			useColor: false,//是否使用自己设定的颜色(startColor和endColor),
			//如果不使用设定的颜色就使用默认的那张网格图
			startColor: '#0F08C8FF',//渐变起始颜色
			endColor: '#7F08C8FF',//渐变结束颜色
			animTime: 2200,//扫描动画时间,单位为毫秒
		};
		moduleScanner.toScannerActivityForResult(params, function (ret, err) {
			//console.log(JSON.stringify(ret));
			var SMequipCode = ret;
			var text = document.getElementById("rsCode");
			text.value = SMequipCode;

		});

	}

	function goSelectChkTask() {
		// var SRequipCode = document.getElementById("rsCode").value;
		// if (SRequipCode == '') {
		// 	//如果为空
		// 	alert("请先扫描资源条码");
		// 	return;
		// }
		var query = api.pageParam.query;
		var type = "";
		if (query.type != undefined && query.type != null && query.type != "") {
			type = query.type;
		}
		var url = "lpaMntTaskSelect.html";
		var title = "点检任务列表";
		api.openWin({
			name: 'about8',
			url: 'about8.html',
			pageParam: {
				url: url,
				title: title,
				//				SRequipCode: SRequipCode,
				type: type
			}
		});
	}

	function setTask(id, taskCode, planCode, chkGid, actualBeginDate, taskState, taskResult, actualEndDate, areaId, areaIdOne) {
		$("#zxResult").val("");
		$api.byId("zxResult").innerHTML = '';
		taskId = id;
		if (taskResult == 1) {
			var str = "<option value='0'>未判定</option><option value='1' selected='true'>OK(未发现问题)</option><option value='2'>NO(发现问题,需要整改)</option>";
			$("#zxResult").append(str);
		} else if (taskResult == 2) {
			var str = "<option value='0'>未判定</option><option value='1'>OK(未发现问题)</option><option value='2' selected='true'>NO(发现问题,需要整改)</option>";
			$("#zxResult").append(str);
		} else {
			var str = "<option value='0' selected='true' >未判定</option><option value='1' >OK(未发现问题)</option><option value='2'>NO(发现问题,需要整改)</option>";
			$("#zxResult").append(str);
		}
		// 获取当前时间
		var currentDate = new Date();

		// 格式化日期时间，例如：YYYY-MM-DD HH:mm:ss
		var formattedDate = currentDate.getFullYear() + '-' +
			('0' + (currentDate.getMonth() + 1)).slice(-2) + '-' +
			('0' + currentDate.getDate()).slice(-2) + ' ' +
			('0' + currentDate.getHours()).slice(-2) + ':' +
			('0' + currentDate.getMinutes()).slice(-2) + ':' +
			('0' + currentDate.getSeconds()).slice(-2);
		$("#chkTaskCode").attr("value", taskCode);
		$("#actualBeginDate").attr("value", formattedDate);
		$("#actualEndDate").attr("value", formattedDate);



		doSearchAreaCodeList(areaId, areaIdOne);

		if ("" != taskId) {
			//选择设备点检任务后，根据任务id获取点检项
			getEquipTaskItemByTask(id, chkGid);

		}
		// console.log(areaIdOne)
		// if(areaIdOne!="" ){
		// 	$("#areaCodeList").attr("value", areaIdOne);
		// }

	}


	function getEquipTaskItemByTask(taskId, chkGid) {
		var serverUrl = localStorage.getItem('serverUrl');
		var url = serverUrl + "/app/getChkItemByTaskLpa";
		var un = localStorage.getItem('un');

		var params = new Object();
		params.url = url;
		params.method = 'post';
		params.dataType = 'json';
		params.returnAll = 'false';
		params.timeout = 60;

		var data = {
			values: {
				un: un,
				taskId: taskId,
				chkGid: chkGid
			}
		};


		api.ajax({
			url: url,
			method: 'post',
			dataType: 'json',
			timeout: 300,
			returnAll: false,
			data: data
		}, function (ret, err) {
			if (ret) {
				var data = JSON.stringify(ret);
				var myobj = eval("(" + data + ")");
				//成功
				if (myobj.code == '0') {
					itemIds = "";
					itemCodes = "";
					itemNames = "";
					itemModes = "";
					itemValues = "";
					itemMaxValues = "";
					itemMinValues = "";
					itemStandardValue = "";
					itemExt01 = "";

					josnList = [];
					var list = myobj.list;
					var html = "";
					var html1 = "";
					html1 += "<tr id='tr1' color: #467aa7;>";
					html1 += "<td style='width:50px;'  algin='center'>序号</td>";
					// html1 += "<td algin='center' style='display:none;'>编号</td>";
					html1 += "<td style='width:250px;' algin='center'>点检项</td>";
					html1 += "<td style='width:250px;' algin='center'>审核标准</td>";
					// html1 += "<td width='15%' algin='center'>最大值</td>";

					// html1 += "<td width='15%' algin='center'>最小值</td>";
					html1 += "<td style='width:200px;' algin='center'>检测值</td>";
					html1 += "<td style='width:250px;' algin='center'>问题描述</td>";
					html1 += "<td style='width:100px;' algin='center'>图片</td>";

					html1 += "<td style='width:200px;' algin='center'>整改负责人</td>";

					html1 += "<td style='width:180px;' algin='center'>要求完成时间</td>";

					// html1 += "<td style='width:250px;' algin='center'>整改要求</td>";

					html1 += "<td style='width:250px;' algin='center'>备注</td></tr>";

					$api.html($api.byId("chkItemTableHead"), html1);
					str = "";
					if (list != undefined) {
						//遍历
						for (var i = 0; i < list.length; i++) {
							var itemId = list[i].itemId;
							var itemCode = list[i].itemCode;
							var itemName = list[i].itemName;
							let formattedItemName = '';
							for (let i = 0; i < itemName.length; i += 15) {
								formattedItemName += itemName.substring(i, i + 15) + '<br>';
							}
							var chkMode = list[i].chkMode;
							var maxValue = list[i].maxValue;
							var chkValue = list[i].chkValue;
							var minValue = list[i].minValue;
							var standardValue = list[i].standardValue;
							var chkResult = list[i].chkResult;
							var ext01 = list[i].ext01;
							let formattedExt01 = '';
							for (let i = 0; i < ext01.length; i += 15) {
								formattedExt01 += ext01.substring(i, i + 15) + '<br>';
							}
							var ext02 = list[i].ext02;
							var remarkIndex = "remark" + i
							var processorsIndex = "processors" + i
							var finishDateIndex = "finishDate" + i
							var problemDescIndex = "problemDesc" + i
							var imgIndex = "index" + i

							if (i == 0) {
								itemIds = itemId + ":" + chkMode;
								itemCodes = itemCode;
								itemNames = itemName;
								itemMaxValues = maxValue;
								itemMinValues = minValue;
								itemStandardValue = standardValue;
								itemExt01 = ext01

							} else {
								itemIds = itemIds + "," + itemId + ":" + chkMode;
								itemCodes = itemCodes + "," + itemCode;
								itemNames = itemNames + "," + itemName;
								itemMaxValues = itemMaxValues + "," + maxValue;
								itemMinValues = itemMinValues + "," + minValue;
								itemStandardValue = itemStandardValue + "," + standardValue;
								itemExt01 = itemExt01 + "," + ext01
							}
							if (chkMode == "0") {
								// str += "<tr ><td width='10%' algin='center'>" + "" + "<input type='checkbox'></td><td algin='center' >"
								//     // + itemCode + "</td><td width='15%' algin='center'>"
								//     + itemName + "</td><td width='15%' algin='center'>"
								//     // + "定性" + "</td><td width='15%' algin='center'>"
								//     + standardValue + "</td><td width='15%' algin='center'>"
								//     + maxValue + "</td><td width='15%' algin='center'>"
								//     + minValue + "</td><td width='15%' algin='left'><select id='"
								//     + itemId + "'><option value='0' selected='true'>未判定</option><option value='1'>不合格</option><option value='5'>放行</option><option value='7'>合格</option></select></td></tr>"
								if (chkResult == "0") {
									str += "<tr ><td style='width:50px;' algin='center'>" +
										"" + "<input type='checkbox' onclick='setDelItem(\"" + itemId + "\");'></td>"
										// + "<td algin='center' style='display:none;'>" + itemCode + "</td>"
										+ "<td style=' max-width: 250px;' algin='center'>" + formattedItemName + "</td>"
										+ "<td style=' max-width: 250px;' algin='center'>" + formattedExt01 + "</td>"
										+ "<td style=' max-width: 250px;' algin='center'><select style='width:200px;' id='" + itemId + "'><option value='0' selected='true'>未判定</option><option value='1'>Y(未发现问题)</option><option value='2'>N(发现问题,不能立即整改)</option><option value='3'>NC(发现问题,已立即整改)</option><option value='4'>N/A(不适用)</option></select></td>"
										+ "<td style=' max-width: 250px;' algin='center'><input style='width:250px;' id='" + problemDescIndex + "' placeholder='请输入' type='text'></input></td>"
										+ "<td style=' max-width: 300px;' algin='center'><img  style='width:100px;height:100px;' src='../image/add.jpg' onclick='imgClickItem(\"" + imgIndex + "\")' id='" + imgIndex + "'></td>"
										+ "<td style=' max-width: 250px;' algin='center'><select style='width:200px;' id='" + processorsIndex + "'></select></td>"
										+ "<td style=' max-width: 250px;' algin='center'><input style='width:180px;' placeholder='请选择' onclick='showTime2(\"" + finishDateIndex + "\")' id='" + finishDateIndex + "' type='text'></input></td>"
										+ "<td style=' max-width: 250px;' algin='center'><input style='width:250px;' id='" + remarkIndex + "' placeholder='请输入'  type='text'></input></td></tr>"
								}
								else if (chkResult == "1") {
									str += "<tr ><td style='width:50px;' algin='center'>" +
										"" + "<input type='checkbox' onclick='setDelItem(\"" + itemId + "\");'></td>"
										// + "<td algin='center' style='display:none;'>" + itemCode + "</td>"
										+ "<td style=' max-width: 250px;' algin='center'>" + formattedItemName + "</td>"
										+ "<td style=' max-width: 250px;' algin='center'>" + formattedExt01 + "</td>"
										+ "<td style=' max-width: 250px;' algin='center'><select style='width:200px;' id='" + itemId + "'><option value='0' >未判定</option><option value='1' selected='true'>Y(未发现问题)</option><option value='2'>N(发现问题,不能立即整改)</option><option value='3'>NC(发现问题,已立即整改)</option><option value='4'>N/A(不适用)</option></select></td>"
										+ "<td style=' max-width: 250px;' algin='center'><input style='width:250px;' id='" + problemDescIndex + "' placeholder='请输入' type='text'></input></td>"
										+ "<td style=' max-width: 300px;' algin='center'><img  style='width:100px;height:100px;' src='../image/add.jpg' onclick='imgClickItem(\"" + imgIndex + "\")' id='" + imgIndex + "'></td>"
										+ "<td style=' max-width: 250px;' algin='center'><select style='width:200px;' id='" + processorsIndex + "'></select></td>"
										+ "<td style=' max-width: 250px;' algin='center'><input style='width:180px;' placeholder='请选择' onclick='showTime2(\"" + finishDateIndex + "\")' id='" + finishDateIndex + "' type='text'></input></td>"
										+ "<td style=' max-width: 250px;' algin='center'><input style='width:250px;' id='" + remarkIndex + "' placeholder='请输入'  type='text'></input></td></tr>"
								} else if (chkResult == "2") {
									str += "<tr ><td style='width:50px;' algin='center'>" +
										"" + "<input type='checkbox' onclick='setDelItem(\"" + itemId + "\");'></td>"
										// + "<td algin='center' style='display:none;'>" + itemCode + "</td>"
										+ "<td style=' max-width: 250px;' algin='center'>" + formattedItemName + "</td>"
										+ "<td style=' max-width: 250px;' algin='center'>" + formattedExt01 + "</td>"
										+ "<td style=' max-width: 250px;' algin='center'><select style='width:200px;' id='" + itemId + "'><option value='0' >未判定</option><option value='1'>Y(未发现问题)</option><option value='2' selected='true'>N(发现问题,不能立即整改)</option><option value='3'>NC(发现问题,已立即整改)</option><option value='4'>N/A(不适用)</option></select></td>"
										+ "<td style=' max-width: 250px;' algin='center'><input style='width:250px;' id='" + problemDescIndex + "' placeholder='请输入' type='text'></input></td>"
										+ "<td style=' max-width: 300px;' algin='center'><img  style='width:100px;height:100px;' src='../image/add.jpg' onclick='imgClickItem(\"" + imgIndex + "\")' id='" + imgIndex + "'></td>"
										+ "<td style=' max-width: 250px;' algin='center'><select style='width:200px;' id='" + processorsIndex + "'></select></td>"
										+ "<td style=' max-width: 250px;' algin='center'><input style='width:180px;' placeholder='请选择' onclick='showTime2(\"" + finishDateIndex + "\")' id='" + finishDateIndex + "' type='text'></input></td>"
										+ "<td style=' max-width: 250px;' algin='center'><input style='width:250px;' id='" + remarkIndex + "' placeholder='请输入'  type='text'></input></td></tr>"
								} else if (chkResult == "3") {
									str += "<tr ><td style='width:50px;' algin='center'>" +
										"" + "<input type='checkbox' onclick='setDelItem(\"" + itemId + "\");'></td>"
										// + "<td algin='center' style='display:none;'>" + itemCode + "</td>"
										+ "<td style=' max-width: 250px;' algin='center'>" + formattedItemName + "</td>"
										+ "<td style=' max-width: 250px;' algin='center'>" + formattedExt01 + "</td>"
										+ "<td style=' max-width: 250px;' algin='center'><select style='width:200px;' id='" + itemId + "'><option value='0' >未判定</option><option value='1'>Y(未发现问题)</option><option value='2'>N(发现问题,不能立即整改)</option><option value='3' selected='true'>NC(发现问题,已立即整改)</option><option value='4'>N/A(不适用)</option></select></td>"
										+ "<td style=' max-width: 250px;' algin='center'><input style='width:250px;' id='" + problemDescIndex + "' placeholder='请输入' type='text'></input></td>"
										+ "<td style=' max-width: 300px;' algin='center'><img  style='width:100px;height:100px;' src='../image/add.jpg' onclick='imgClickItem(\"" + imgIndex + "\")' id='" + imgIndex + "'></td>"
										+ "<td style=' max-width: 250px;' algin='center'><select style='width:200px;' id='" + processorsIndex + "'></select></td>"
										+ "<td style=' max-width: 250px;' algin='center'><input style='width:180px;' placeholder='请选择' onclick='showTime2(\"" + finishDateIndex + "\")' id='" + finishDateIndex + "' type='text'></input></td>"
										+ "<td style=' max-width: 250px;' algin='center'><input style='width:250px;' id='" + remarkIndex + "' placeholder='请输入'  type='text'></input></td></tr>"
								} else if (chkResult == "4") {
									str += "<tr ><td style='width:50px;' algin='center'>" +
										"" + "<input type='checkbox' onclick='setDelItem(\"" + itemId + "\");'></td>"
										// + "<td algin='center' style='display:none;'>" + itemCode + "</td>"
										+ "<td style=' max-width: 250px;' algin='center'>" + formattedItemName + "</td>"
										+ "<td style=' max-width: 250px;' algin='center'>" + formattedExt01 + "</td>"
										+ "<td style=' max-width: 250px;' algin='center'><select style='width:200px;' id='" + itemId + "'><option value='0' >未判定</option><option value='1'>Y(未发现问题)</option><option value='2'>N(发现问题,不能立即整改)</option><option value='3'>NC(发现问题,已立即整改)</option><option value='4' selected='true'>N/A(不适用)</option></select></td>"
										+ "<td style=' max-width: 250px;' algin='center'><input style='width:250px;' id='" + problemDescIndex + "' placeholder='请输入' type='text'></input></td>"
										+ "<td style=' max-width: 300px;' algin='center'><img  style='width:100px;height:100px;' src='../image/add.jpg' onclick='imgClickItem(\"" + imgIndex + "\")' id='" + imgIndex + "'></td>"
										+ "<td style=' max-width: 250px;' algin='center'><select style='width:200px;' id='" + processorsIndex + "'></select></td>"
										+ "<td style=' max-width: 250px;' algin='center'><input style='width:180px;' placeholder='请选择' onclick='showTime2(\"" + finishDateIndex + "\")' id='" + finishDateIndex + "' type='text'></input></td>"
										+ "<td style=' max-width: 250px;' algin='center'><input style='width:250px;' id='" + remarkIndex + "' placeholder='请输入'  type='text'></input></td></tr>"
								}

							}
							if (chkMode == "1") {
								str += "<tr ><td width='10%' algin='center'>" + "" + "<input type='checkbox'></td><td algin='center' >"
									// + itemCode + "</td><td width='15%' algin='center'>"
									+ itemName + "</td><td width='15%' algin='center'>"
									// + "定量" + "</td><td width='15%' algin='center'>"
									+ ext01 + "</td><td width='15%' algin='left'>" + "<input id='"
									+ itemId + "' type='text' value='"

									+ chkValue + "'></td></tr>"
							}
							// if (chkMode == "0") {
							// 	if (chkResult == "1") {
							// 		str += "<tr ><td width='10%' algin='center'>" +
							// 			"" + "<input type='checkbox' onclick='setDelItem(\"" + itemId + "\");'></td><td algin='center' style='display:none;'>"
							// 			+ itemCode + "</td><td width='25%' algin='center'>"
							// 			+ itemName + "</td><td width='15%' algin='center'>"
							// 			+ maxValue + "</td><td width='15%' algin='center'>"
							// 			+ standardValue + "</td><td width='15%' algin='center'>"
							// 			+ minValue + "</td><td width='25%' algin='left'><select id='"
							// 			+ itemId + "'><option value='0'>未判定</option><option value='1' selected='true'>正常</option><option value='2'>异常</option></select></td></tr>"
							// 	} else if (chkResult == "2") {
							// 		str += "<tr ><td width='10%' algin='center'>" + "" + "<input type='checkbox' onclick='setDelItem(\"" + itemId + "\");'></td><td algin='center' style='display:none;'>"
							// 			+ itemCode + "</td><td width='25%' algin='center'>"
							// 			+ itemName + "</td><td width='15%' algin='center'>"
							// 			+ maxValue + "</td><td width='15%' algin='center'>"
							// 			+ standardValue + "</td><td width='15%' algin='center'>"
							// 			+ minValue + "</td><td width='25%' algin='left'><select id='"
							// 			+ itemId + "'><option value='0'>未判定</option><option value='1'>正常</option><option value='2' selected='true'>异常</option></select></td></tr>"
							// 	} else {
							// 		str += "<tr ><td width='10%' algin='center'>" + "" + "<input type='checkbox' onclick='setDelItem(\""
							// 			+ itemId + "\");'></td><td algin='center' style='display:none;'>"
							// 			+ itemCode + "</td><td width='25%' algin='center'>"
							// 			+ itemName + "</td><td width='15%' algin='center'>"
							// 			+ maxValue + "</td><td width='15%' algin='center'>"
							// 			+ standardValue + "</td><td width='15%' algin='center'>"
							// 			+ minValue + "</td><td width='25%' algin='left'><select id='"
							// 			+ itemId + "'><option value='0' selected='true'>未判定</option><option value='1'>正常</option><option value='2'>异常</option></select></td></tr>"
							// 	}

							// }
							// if (chkMode == "1") {
							// 	str += "<tr ><td width='10%' algin='center'>" + "" + "<input type='checkbox' onclick='setDelItem(\"" + itemId + "\");'></td><td algin='center' style='display:none;'>" + itemCode + "</td><td width='50%' algin='center'>" + itemName + "</td><td width='15%' algin='center'>" + standardValue + "</td><td width='25%' algin='center'><input id='" + itemId + "' type='text' value='" + chkValue + "'></td></tr>"
							// }
							//$("#chkItemTable").append(str);
							// console.log(itemMaxValues);
							// console.log(itemMinValues);
						}
					}
					$("#chkItemTableHead").append(str);
					//$api.html($api.byId("chkItemTableBody"), str);

				} else if (myobj.code == '1') {
					api.toast({
						msg: myobj.message,
						duration: 3000
					});
				}
			}
		});
	}
	/* 
		function setAddItem(itemStrs) {
			if (itemStrs == "") {
				//未添加点检项
			} else {
				//将选择添加的点检项添加到表格中
				var itemStrArr = itemStrs.split(",");
				// alert(itemStrArr);
				var trStr = "";
				var nums = itemIds.split(",").length;
				var nums2 = itemIds.split(",");
				for (i = 0; i < itemStrArr.length; i++) {
					var itemArr = itemStrArr[i].split(":");
					console.log(itemArr);
					var id = itemArr[0];
					var code = itemArr[1];
					var name = itemArr[2];
					var mode = itemArr[3];
					var maxValue = itemArr[4];
					var minValue = itemArr[5];
					var standardValue = itemArr[6];
	
					if (itemIds == "") {
						itemIds = id + ":" + mode;
						itemCodes = code;
						itemNames = name;
					} else {
						itemIds = itemIds + "," + id + ":" + mode;
						itemCodes = itemCodes + "," + code;
						itemNames = itemNames + "," + name;
					}
					// alert("nums : " + nums)
					// alert("nums2 : " + nums2)
					// alert("mode : " + mode)
					if (nums == 1) {
						if (nums2 == "") {
							if (mode == "0") {
								trStr = "<tr ><td width='10%' algin='center'>" + "" + "<input type='checkbox' onclick='setDelItem(\""
									+ id + "\");'></td><td algin='center' style='display:none;'>"
									+ code + "</td><td width='25%' algin='center'>"
									+ name + "</td><td width='15%' algin='center'>"
									+ maxValue + "</td><td width='15%' algin='center'>"
									+ standardValue + "</td><td width='15%' algin='center'>"
									+ minValue + "</td><td width='30%' algin='left'><select id='"
									+ id + "'><option value='0' selected='true'>未判定</option><option value='1'>正常</option><option value='2'>异常</option></select></td></tr>"
							}
							if (mode == "1") {
								trStr = "<tr ><td width='10%' algin='center'>" + "" + "<input type='checkbox' onclick='setDelItem(\""
									+ id + "\");'></td><td algin='center' style='display:none;'>"
									+ code + "</td><td width='25%' algin='center'>"
									+ name + "</td><td width='15%' algin='center'>"
									+ maxValue + "</td><td width='15%' algin='center'>"
									+ standardValue + "</td><td width='15%' algin='center'>"
									+ minValue + "</td><td width='30%' algin='center'><input id='"
									+ id + "' type='text' value=''></td></tr>"
							}
						} else {
							if (mode == "0") {
								trStr = "<tr ><td width='10%' algin='center'>" + "" + "<input type='checkbox' onclick='setDelItem(\""
									+ id + "\");'></td><<td algin='center' style='display:none;'>"
									+ code + "</td><td width='25%' algin='center'>"
									+ name + "</td><td width='15%' algin='center'>"
									+ maxValue + "</td><td width='15%' algin='center'>"
									+ standardValue + "</td><td width='15%' algin='center'>"
									+ minValue + "</td><td width='30%' algin='left'><select id='"
									+ id + "'><option value='0' selected='true'>未判定</option><option value='1'>正常</option><option value='2'>异常</option></select></td></tr>"
							}
							if (mode == "1") {
								trStr = "<tr ><td width='10%' algin='center'>" + "" + "<input type='checkbox' onclick='setDelItem(\""
									+ id + "\");'></td><td algin='center' style='display:none;'>"
									+ code + "</td><td width='25%' algin='center'>"
									+ name + "</td><td width='15%' algin='center'>"
									+ maxValue + "</td><td width='15%' algin='center'>"
									+ standardValue + "</td><td width='15%' algin='center'>"
									+ minValue + "</td><td width='30%' algin='center'><input id='"
									+ id + "' type='text' value=''></td></tr>"
							}
						}
					} else {
						if (mode == "0") {
							trStr = "<tr ><td width='10%' algin='center'>" + "" + "<input type='checkbox' onclick='setDelItem(\""
								+ id + "\");'></td><td algin='center' style='display:none;'>"
								+ code + "</td><<td width='25%' algin='center'>"
								+ name + "</td><td width='15%' algin='center'>"
								+ maxValue + "</td><td width='15%' algin='center'>"
								+ standardValue + "</td><td width='15%' algin='center'>"
								+ minValue + "</td><td width='30%' algin='left'><select id='"
								+ id + "'><option value='0' selected='true'>未判定</option><option value='1'>正常</option><option value='2'>异常</option></select></td></tr>"
						}
						if (mode == "1") {
							trStr = "<tr ><td width='10%' algin='center'>" + "" + "<input type='checkbox' onclick='setDelItem(\""
								+ id + "\");'></td><td algin='center' style='display:none;'>"
								+ code + "</td><td width='25%' algin='center'>"
								+ name + "</td><td width='15%' algin='center'>"
								+ maxValue + "</td><td width='15%' algin='center'>"
								+ standardValue + "</td><td width='15%' algin='center'>"
								+ minValue + "</td><td width='30%' algin='center'><input id='"
								+ id + "' type='text' value=''></td></tr>"
						}
					}
	
					$("#chkItemTableHead").append(trStr);
				}
				if (trStr != "") {
	
					//	$("#chkItemTableBody").append(trStr);
				}
			}
		} */

	/* function doAdd() {
		var taskCode = $("#chkTaskCode").val();
		//	alert(itemCodes);
		if (taskCode != "") {
			//根据现有的点检项，获取新的点检项		
			var url = "selEquipItemList.html";
			var title = "设备检测项列表";
			api.openWin({
				name: 'equipItem',
				url: url,
				pageParam: {
					title: title,
					itemCodes: itemCodes
				}
			});
		} else {
			alert("请选择点检任务");
		}
	} */



	function setDelItem(id) {
		if (delItemIds == "") {
			delItemIds = id;
		} else {
			if (delItemIds.indexOf(id) > 0) {
				//已存在
				var delArr = delItemIds.split(",");
				delItemIds = "";
				for (i = 0; i < delArr.length; i++) {
					if (delArr[i] != id) {
						if (i == 0) {
							delItemIds = delArr[i];
						} else {
							delItemIds = delItemIds + "," + delArr[i];
						}
					}

				}
			} else {
				//不存在
				delItemIds = delItemIds + "," + id;
			}
		}
	}




	/* 	function doDel() {
			if (delItemIds != "") {
				//过滤掉要删除的点检项
				setItemValues();
	
	
				var idArr = itemIds.split(",");
				var codeArr = itemCodes.split(",");
				var nameArr = itemNames.split(",");
				var maxValueArr = itemMaxValues.split(",");
				var minValueArr = itemMinValues.split(",");
				var standardValueArr = itemStandardValue.split(",");
				var valueArr = itemValues.split(",");
	
				itemIds = "";
				itemCodes = "";
				itemNames = "";
				maxValues = "";
				minValues = "";
				standardValues = "";
				josnList = [];
	
				var itemIdStr = "";
	
				//$("#chkItemTableHead").children().remove();
				$("#chkItemTableHead").children().remove();
				$("#chkItemTableHead").append("<tr id='tr1'><td width='10%' algin='center'>序号</td><td width='10%' algin='center'>编号</td><td width='25%' algin='center'>点检项</td><td width='15%' algin='center'>最大值</td><td width='15%' algin='center'>标准值</td><td width='15%' algin='center'>最小值</td><td width='30%' algin='center'>检测值</td></tr>");
				//var html = "<tr id='tr1'><td width='10%' algin='center'>序号</td><td width='10%' algin='center'>编号</td><td width='50%' algin='center'>点检项</td><td width='30%' algin='center'></td></tr>";
				//$api.html($api.byId("chkItemTableHead"), html);
				var seq = 0;
				for (i = 0; i < idArr.length; i++) {
					itemIdStr = idArr[i].split(":")[0];
					if (delItemIds.indexOf(itemIdStr) < 0) {
						seq++;
						//不在要删除的id字符串中
						var strDel = "";
						if (i == 0) {
							itemIds = idArr[i];
							itemCodes = codeArr[i];
							itemNames = nameArr[i];
							maxValues = maxValueArr[i];
							minValues = minValueArr[i];
							standardValues = standardValueArr[i];
						} else {
							itemIds = itemIds + "," + idArr[i];
							itemCodes = itemCodes + "," + codeArr[i];
							itemNames = itemNames + "," + nameArr[i];
							maxValues = maxValues + "," + maxValueArr[i];
							minValues = minValues + "," + minValueArr[i];
							standardValues = standardValues + "," + standardValueArr[i];
						}
						if (idArr[i].split(":")[1] == "0") {
							if (valueArr[i] == "1") {
								strDel = "<tr ><td width='10%' algin='center'><input type='checkbox' onclick='setDelItem(\""
									+ itemIdStr + "\");'></td><td width='10%' algin='center style='display:none; '>"
									+ codeArr[i] + "</td><td width='25%' algin='center'>"
									+ nameArr[i] + "</td><td width='15%' algin='center'>"
									+ maxValueArr[i] + "</td><td width='15%' algin='center'>"
									+ minValueArr[i] + "</td><td width='15%' algin='center'>"
									+ standardValueArr[i] + "</td><td width='30%' algin='left'><select id='"
									+ itemIdStr + "'><option value='0'>未判定</option><option value='1' selected='true'>正常</option><option value='2'>异常</option></select></td></tr>"
							} else if (valueArr[i] == "2") {
								strDel = "<tr ><td width='10%' algin='center'><input type='checkbox' onclick='setDelItem(\""
									+ itemIdStr + "\");'></td><td width='10%' algin='center style='display:none; '>"
									+ codeArr[i] + "</td><td width='25%' algin='center'>"
									+ nameArr[i] + "</td><td width='15%' algin='center'>"
									+ maxValueArr[i] + "</td><td width='15%' algin='center'>"
									+ minValueArr[i] + "</td><td width='15%' algin='center'>"
									+ standardValueArr[i] + "</td><td width='30%' algin='left'><select id='"
									+ itemIdStr + "'><option value='0'>未判定</option><option value='1'>正常</option><option value='2' selected='true'>异常</option></select></td></tr>"
							} else {
								strDel = "<tr ><td width='10%' algin='center'><input type='checkbox' onclick='setDelItem(\""
									+ itemIdStr + "\");'></td><td width='10%' algin='center style='display:none; '>"
									+ codeArr[i] + "</td><td width='25%' algin='center'>"
									+ nameArr[i] + "</td><td width='15%' algin='center'>"
									+ maxValueArr[i] + "</td><td width='15%' algin='center'>"
									+ minValueArr[i] + "</td><td width='15%' algin='center'>"
									+ standardValueArr[i] + "</td><td width='30%' algin='left'><select id='"
									+ itemIdStr + "'><option value='0' selected='true'>未判定</option><option value='1'>正常</option><option value='2'>异常</option></select></td></tr>"
							}
	
						}
						if (idArr[i].split(":")[1] == "1") {
							strDel = "<tr ><td width='10%' algin='center'><input type='checkbox' onclick='setDelItem(\""
								+ itemIdStr + "\");'></td><td width='10%' algin='center style='display:none; '>"
								+ codeArr[i] + "</td><td width='25%' algin='center'>"
								+ nameArr[i] + "</td><td width='15%' algin='center'>"
								+ maxValueArr[i] + "</td><td width='15%' algin='center'>"
								+ minValueArr[i] + "</td><td width='15%' algin='center'>"
								+ standardValueArr[i] + "</td><td width='30%' algin='center'><input id='"
								+ itemIdStr + "' type='text' value='"
								+ valueArr[i] + "'></td></tr>"
						}
	
						$("#chkItemTableHead").append(strDel);
						//$api.html($api.byId("chkItemTableBody"), strDel);
					}
				}
				delItemIds = "";
			} else {
				alert("未选择要删除的点检项");
			}
		} */


	function doSave(type) {
		if (itemIds != "") {
			//点检项表格中有数据
			setItemValues();
		} else {
			alert("无点检项信息，无法提交数据");
		}
	}

	function setItemValues() {
		var itemIdArr = itemIds.split(",");
		console.log(JSON.stringify(itemIdArr))
		var itemValue = "";
		var un = localStorage.getItem('un');
		// 定义一个数组存储符合条件的 src 值

		for (i = 0; i < itemIdArr.length; i++) {
			var imgSrcList = [];
			var itemStrArr = itemIdArr[i].split(":");
			var itemCodeArr = itemCodes.split(",");
			var itemNameArr = itemNames.split(",");
			var itemMaxValueArr = itemMaxValues.split(",");
			var itemMinValueArr = itemMinValues.split(",");
			var chkValue = "";
			var checkResult = "";
			// var remark = itemIdArr[i].remark;
			var taskState = document.getElementById("zxState").value;
			var taskResult = document.getElementById("zxResult").value;
			var actualBeginDate = document.getElementById("actualBeginDate").value;
			var actualEndDate = document.getElementById("actualEndDate").value;
			var remarkIndex = "remark" + i
			var processorsIndex = "processors" + i
			var imgIndex = "imgindex" + i; // 动态生成的 img ID
			var finishDateIndex = "finishDate" + i
			// var countermeasureIndex = "countermeasure" + i
			var problemDescIndex = "problemDesc" + i

			// var imgElements = document.getElementsByClassName(imgIndex); // 获取 img 元素

			// if (imgElements.length > 0) {
			// 	// 遍历 imgElements 中的每个 img 元素
			// 	for (var i = 0; i < imgElements.length; i++) {
			// 		var imgElement = imgElements[i]; // 获取每个 img 元素
			// 		var imgSrc = imgElement.getAttribute("src"); // 获取 src 属性
			// 		imgSrcList.push(imgSrc);
			// 	}
			// }

			// 使用 querySelectorAll 获取所有指定类名的 img 元素（静态 NodeList）
			var imgElements = document.querySelectorAll('.' + imgIndex);

			// 直接使用 forEach 遍历 img 元素列表，避免手动写 for 循环
			imgElements.forEach(function (imgElement) {
				var imgSrc = imgElement.src; // 使用 imgElement.src 获取 src 属性，这比 getAttribute 快
				imgSrcList.push(imgSrc);
			});

			// 获取 <td> 内对应 <input> 的值
			var remarkInputValue = ""; // 初始化备注值
			if (remarkIndex) {
				var remarkInput = document.getElementById(remarkIndex); // 通过 remark 获取 input 元素
				if (remarkInput) {
					remarkInputValue = remarkInput.value; // 获取 input 的值
				}
			}

			// 获取 <td> 内对应 <input> 的值
			var processorsSelectValue = ""; // 初始化备注值
			if (processorsIndex) {
				var processorsSelect = document.getElementById(processorsIndex); // 通过 remark 获取 input 元素
				if (processorsSelect) {
					processorsSelectValue = processorsSelect.value; // 获取 input 的值
				}
			}

			// 获取 <td> 内对应 <input> 的值
			var finishDateIndexValue = ""; // 初始化备注值
			if (finishDateIndex) {
				var finishDate2 = document.getElementById(finishDateIndex); // 通过 remark 获取 input 元素
				if (finishDate2) {
					finishDateIndexValue = finishDate2.value; // 获取 input 的值
				}
			}

			// 获取 <td> 内对应 <input> 的值
			var problemDescIndexValue = ""; // 初始化备注值
			if (problemDescIndex) {
				var problemDescIndex2 = document.getElementById(problemDescIndex); // 通过 remark 获取 input 元素
				if (problemDescIndex2) {
					problemDescIndexValue = problemDescIndex2.value; // 获取 input 的值
				}
			}

			if (itemStrArr[1] == "0") {
				//获取下拉框选中的值
				itemValue = document.getElementById(itemStrArr[0]).value;//选中的值
				checkResult = itemValue;
				if (checkResult == '2' || checkResult == '3') {
					var zxResultFlag = $("#zxResult").val();
					if (zxResultFlag == '1') {
						api.toast({
							msg: '存在审核项结果为N或N/C，执行结果不能为OK！',
							duration: 3000
						});
						return;
					}
					if (processorsSelectValue == null || processorsSelectValue == '' || processorsSelectValue == undefined) {
						api.toast({
							msg: '存在审核项结果为N或N/C，必须选择整改负责人！',
							duration: 3000
						});
						return;
					}
				}
			}
			if (itemStrArr[1] == "1") {
				//获取文本框填的值
				itemValue = document.getElementById(itemStrArr[0]).value
				chkValue = itemValue;
				if (parseFloat(chkValue) >= parseFloat(itemMinValueArr[i]) && parseFloat(chkValue) <= parseFloat(itemMaxValueArr[i])) {
					//检验结果 0未判定/1正常/2异常
					checkResult = 1;
				} else {
					checkResult = 2;
				}
			}

			if (i == 0) {
				itemValues = itemValue;
			} else {
				itemValues = itemValues + "," + itemValue;
			}
			//将点检项的结果转化为jsonList
			var chkBeginTime = document.getElementById("actualBeginDate").value;
			var iObj = new itemObj(itemStrArr[0], itemCodeArr[i], itemNameArr[i], chkValue, checkResult, un, taskState, taskResult, chkBeginTime, remarkInputValue, imgSrcList, processorsSelectValue, finishDateIndexValue, problemDescIndexValue);
			josnList.push(iObj);
		}
		//提交数据到服务端
		doSubmit();
	}


	function itemObj(chkItemId, chkItemCode, chkItemName, chkValue, checkResult, chkPerson, taskState, taskResult, chkBeginTime, remark, imgSrcList, processorsSelectValue, finishDateIndexValue, problemDescIndexValue) {
		this.chkItemGid = chkItemId;
		this.chkItemCode = chkItemCode;
		this.chkItemName = chkItemName;
		this.chkValue = chkValue;
		this.checkResult = checkResult;
		this.taskState = taskState;
		this.taskResult = taskResult;
		this.chkBeginTime = chkBeginTime;
		this.remark = remark;
		this.imgSrcList = imgSrcList;
		this.processorsSelectValue = processorsSelectValue;
		this.finishDateIndexValue = finishDateIndexValue;
		this.problemDescIndexValue = problemDescIndexValue
	}

	function HCObj(HCId, mrlGid, mrlCode, mrlName, qty, consumeType, remark, operPerson, operType) {
		this.HCId = HCId;
		this.mrlGid = mrlGid;
		this.mrlCode = mrlCode;
		this.mrlName = mrlName;
		this.qty = qty;
		this.consumeType = consumeType;
		this.remark = remark;
		this.operPerson = operPerson;
		this.operType = operType;
	}

	function YqObj(taskPartGid, mrlGid, mrlCode, mrlName, remark, operPerson, operType) {
		this.taskPartGid = taskPartGid;
		this.mrlGid = mrlGid;
		this.mrlCode = mrlCode;
		this.mrlName = mrlName;
		this.remark = remark;
		this.operPerson = operPerson;
		this.operType = operType;
	}

	function doSubmit() {
		if (!clickThrottle()) {
			return;
		}
		var type = document.getElementById("zxResult").value;
		var taskState = document.getElementById("zxState").value;
		// var processors = document.getElementById("processors").value;
		var areaSysid = document.getElementById("areaCodeList").value;

		// var measures = document.getElementById("measures").value;
		// var finishDate = document.getElementById("finishDate").value;
		// var countermeasure = document.getElementById("countermeasure").value;


		if (areaSysid == "" || areaSysid == null || areaSysid == undefined) {
			api.toast({
				msg: '请选择区域！',
				duration: 3000
			});
			return;
		}

		// if (type == '2' && taskState == '3') {
		// 	if (processors == "" || processors == null || processors == undefined) {
		// 		api.toast({
		// 			msg: '请选择审核区域负责人！',
		// 			duration: 3000
		// 		});
		// 		return;
		// 	}
		// }
		// var imgs = document.querySelectorAll('li img');
		// var names = [];
		// for (var i = 0; i < imgs.length; i++) {
		// 	var img = imgs[i];
		// 	var srcStr = img.getAttribute('src');
		// 	var arrs = srcStr.split('\/');
		// 	var nameStr = arrs[arrs.length - 1];
		// 	//alert(nameStr);
		// 	if ("add.jpg" != nameStr) {
		// 		names[i] = nameStr;
		// 	}
		// }
		// var picNames = JSON.parse(JSON.stringify(names));
		var actualBeginDate = document.getElementById("actualBeginDate").value;
		var actualEndDate = document.getElementById("actualEndDate").value;
		api.showProgress();
		//var rsCode = document.getElementById("rsCode").value;
		var serverUrl = localStorage.getItem('serverUrl');
		var url = serverUrl + "/app/saveTaskItem2SH";
		var un = localStorage.getItem('un');
		// var pw = localStorage.getItem('pw');
		// var serverIp = localStorage.getItem('serverIp');
		// var serverPort = localStorage.getItem('serverPort');
		// var serverProject = localStorage.getItem('serverProject');
		// var url1 = serverIp+":"+serverPort+"/"+serverProject;

		const submitButton = document.getElementById('submitButton');
		submitButton.style.pointerEvents = "none"

		var params = new Object();
		params.url = url;
		params.method = 'post';
		params.dataType = 'json';
		params.returnAll = 'false';
		params.timeout = 60;

		api.showProgress({
			title: '保存中...',
		});

		var data = {
			values: {
				un: un,
				// pw: pw,
				// url: url1,
				taskId: taskId,
				rowData: JSON.stringify(josnList),
				type: type,
				taskState: taskState,
				//rsCode: rsCode,
				actualBeginDate: actualBeginDate,
				actualEndDate: actualEndDate,
				// processors: processors,
				areaSysid: areaSysid,
				// measures: measures,
				// finishDate: finishDate,
				// countermeasure: countermeasure,
				// picNames: picNames,
			}
		};

		api.ajax({
			url: url,
			method: 'post',
			dataType: 'json',
			timeout: 300,
			returnAll: false,
			data: data
		}, function (ret, err) {
			if (ret) {
				var data = JSON.stringify(ret);
				var myobj = eval("(" + data + ")");
				//成功
				if (myobj.code == '0') {

					api.hideProgress();
					submitButton.style.pointerEvents = "auto"
					api.toast({
						msg: "保存成功",
						duration: 3000
					});
					//清空所有信息，重新扫设备选任务
					taskId = "";
					taskCode = "";
					itemIds = "";
					itemCodes = "";
					itemNames = "";
					itemModes = "";
					itemValues = "";
					josnList = [];

					HCIds = "";
					mrlGids = "";
					mrlCodes = "";
					mrlNames = "";
					mrlExNames = "";
					qtys = "";
					measureNames = "";
					consumeTypes = "";
					remarks = "";
					josnHCList = [];

					YqIds = "";
					mrlYqGids = "";
					mrlYqCodes = "";
					mrlYqNames = "";
					remarkYqs = "";
					josnYqList = [];
					//清空设备扫码框				
					$("#rsCode").val("").focus();
					// 清空执行状态					
					$("#zxState").val("");
					// 清空执行结果					
					$("#zxResult").val("");
					$api.byId("areaCodeList").innerHTML = '';
					$api.byId("zxResult").innerHTML = '';

					// 清空执行时间
					$("#actualBeginDate").attr("value", "");
					// 清空执行时间
					$("#actualEndDate").attr("value", "");
					//清空任务选择
					$("#chkTaskCode").attr("value", "");

					$("#measures").attr("value", "");

					$("#finishDate").attr("value", "");

					$("#countermeasure").attr("value", "");

					//清空点检项表格
					$("#chkItemTableHead").children().remove();
					//$api.html($api.byId("chkItemTableHead"), "");
					// 清除检测维修耗材表格
					$("#chkHCTableHead").children().remove();
					//$api.html($api.byId("chkHCTableHead"), "");
					// 清除检测维修仪器表格
					$("#chkYqTableHead").children().remove();
					//$api.html($api.byId("chkYqTableHead"), "");
					var imgs = document.getElementsByTagName('img');

					// 获取包含要移除图片的 li 元素
					var liElement = document.getElementById('test'); // 请将 'yourLiId' 替换为实际的 li 元素的 id

					// 如果找到了 li 元素，则从其父元素中移除它
					if (liElement) {
						liElement.parentNode.removeChild(liElement);
					}

					for (var i = 0; i < imgs.length; i++) {
						imgs[i].alt = ''; // 清除图片的 alt 属性值
						// 如果还有其他属性需要清除，可以继续添加类似的语句
					}
				} else if (myobj.code == '1') {
					api.hideProgress();
					submitButton.style.pointerEvents = "auto"
					api.toast({
						msg: myobj.message,
						duration: 3000
					});
				}
			} else {
				api.hideProgress();
				submitButton.style.pointerEvents = "auto"
				alert(JSON.stringify(err));
			}
			Hide()
		});
	}

	function imgClickItem(index) {
		var imgIndexNew = index
		var imgIndex = "img" + index
		api.actionSheet({
			title: '选择图片来源',
			buttons: ['照相机', '浏览相册']
		}, function (ret, err) {
			var index = ret.buttonIndex;
			switch (index) {
				// 拍照
				case 1:
					// 打开拍照
					api.getPicture({
						sourceType: "camera",
						encodingType: "jpg",
						destinationType: "url",
						mediaValue: "pic",
						quality: 50,
						saveToPhotoAlbum: true
					}, function (ret, err) {
						if (ret && ret.data) {
							// 拍照返回的本地路径
							var returnUrl = ret.data;
							// 图片压缩
							imgCompress(returnUrl, 0.5, 0.5, getExt(returnUrl), function (compressImg) {
								var showImgHtml = "<img algin='center' class='" + imgIndex + "'  style='width:100px;height:100px;' src='" + compressImg + "'>"
								// 追加图片
								var imgIn = "#" + imgIndexNew
								$(imgIn).before(showImgHtml);

								// // ########################################  绑定长按事件 ########################
								// 绑定长按事件
								addPress($(imgIn).prev("img"));
								//上传图片
								uploadFile(compressImg);
							});
						} else {
							api.toast({
								msg: '没有选择，或者选择出错'
							});
						}
					});
					break;
				// 打开图片选择器
				case 2:
					uiMediaScanner.open({
						type: 'picture',
						column: 4,
						classify: true,
						max: 5,
						sort: {
							key: 'time',
							order: 'desc'
						},
						texts: {
							stateText: '已选*项',
							cancelText: '取消',
							finishText: '完成'
						},
						styles: {
							bg: '#fff',
							mark: {
								icon: '',
								position: 'bottom_left',
								size: 20
							},
							nav: {
								bg: '#b23e4b',
								stateColor: '#fff',
								stateSize: 18,
								cancelBg: 'rgba(0,0,0,0)',
								cancelColor: '#fff',
								cancelSize: 18,
								finishBg: 'rgba(0,0,0,0)',
								finishColor: '#fff',
								finishSize: 18
							}
						}
					}, function (ret) {
						if (ret) {
							if (ret.list) {
								for (var i = 0; i < ret.list.length; i++) {
									var selectImg = ret.list[i];
									// 获取图片的路径
									var selectimgPath = selectImg.path;
									var selectimgThumbPath = selectImg.thumbPath;
									// 图片压缩
									imgCompress(selectimgPath, 0.5, 0.5, selectImg.suffix, function (compressImg) {
										var showImgHtml = "<img algin='center' class='" + imgIndex + "'  style='width:100px;height:100px;' src='" + compressImg + "'>"
										// 追加图片
										var imgIn = "#" + imgIndex
										$(imgIn).before(showImgHtml);
										// ########################################  绑定长按事件 ########################
										// 绑定长按事件
										addPress($(imgIn).prev("img"));

										// ################### 上传图片 #########################
										uploadFile(compressImg);
									});
								}
							}
						}
					});
					break;
			}
		});
	}

	// 图片压缩
	// imgsrc：源图片的路径
	// quality：图片压缩质量，一般建议0.5
	// scale：图片压缩比例，也是建议0.5
	// ext：源图片拓展名
	// callback：转换成功之后回调函数
	function imgCompress(imgsrc, quality, scale, ext, callback) {
		// 压缩文件的保存目录
		var savePath = api.cacheDir + "/" + getNowFormatDate() + "/";
		// 压缩文件生成的随机文件名称
		var savename = NewGuid() + "." + ext;
		imageFilter.compress({
			img: imgsrc,
			quality: quality,
			scale: quality,
			save: {
				album: false,
				imgPath: savePath,
				imgName: savename
			}
		}, function (ret, err) {
			if (ret) {
				callback(savePath + savename);
			} else {
				alert(JSON.stringify(err));
			}
		});
	}

	// 打开图片浏览
	// imgs：需要预览的图片集合
	function openImageBrowser(imgs) {
		imageBrowser.openImages({
			imageUrls: imgs,
			showList: false,
			activeIndex: 0
		});
	}

	// 获取当前的时间，拼接成2015-11-09这样的格式，主要用于对图片进行时间分类
	function getNowFormatDate() {
		var date = new Date();
		var seperator1 = "-";
		var year = date.getFullYear();
		var month = date.getMonth() + 1;
		var strDate = date.getDate();
		if (month >= 1 && month <= 9) {
			month = "0" + month;
		}
		if (strDate >= 0 && strDate <= 9) {
			strDate = "0" + strDate;
		}
		var currentdate = year + seperator1 + month + seperator1 + strDate
		return currentdate;
	}

	// 获取文件拓展名
	function getExt(fileName) {
		return fileName.substring(fileName.lastIndexOf('.') + 1);
	}

	// 生成guid,主要用于生成随机文件名
	function NewGuid() {
		function S4() {
			return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
		}

		return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
	}

	// 添加长按方法
	function addPress(obj, index) {
		// 获取目前长按的对象
		var hammertime = new Hammer(obj[0]);
		// 绑定长按对象
		hammertime.on("press", function (e) {
			api.confirm({
				title: '温馨提示',
				msg: '您确定要删除该图片吗？',
				buttons: ['确定', '取消']
			}, function (ret, err) {
				if (ret.buttonIndex == 1) {
					// 移除自己
					$(obj).remove();
					api.toast({
						msg: '删除成功！'
					});
				}
			});
		});
	}

	// 上传图片
	// url：上传的url地址
	// data：上传的文件
	// callback：上传成功返回地址
	function uploadFile(data) {
		var un = localStorage.getItem('un');
		var serverUrl = localStorage.getItem('serverUrl');
		var url = serverUrl + "/app/uploadPhotosAPP";
		var data = {
			values: {
				un: un
			},
			files: {
				file: data
			}
		};
		api.ajax({
			url: url,
			method: 'post',
			dataType: 'json',
			timeout: 300,
			returnAll: false,
			data: data
		}, function (ret, err) {
			if (ret) {
				var data = JSON.stringify(ret);
				var myobj = eval("(" + data + ")");
				if (myobj.code == "0") {
					console.log("上传成功");
				} else if (myobj.code == "1") {
					alert("上传失败");
				}
			} else {
				alert(JSON.stringify(err));
			}
		});
	}


	//返回按钮
	function closeWin() {
		api.closeWin({});
	}
</script>

</html>